<template>
  <div class="container">
    <div
        class="form-box"
        :style="{ transform: `translateX(${formTranslation}%)` }"
    >
      <!-- 注册 -->
      <div class="register-box" :class="{ hidden: !isRegister }">
        <h1>REGISTER</h1>
        <el-form>
          <el-form-item>
            <el-input
                placeholder="用户名"
                v-model="registerUsername"
                clearable
            />
          </el-form-item>
          <el-form-item>
            <el-input
                type="email"
                placeholder="邮箱"
                v-model="registerEmail"
                clearable
            />
          </el-form-item>
          <el-form-item>
            <el-input
                type="password"
                placeholder="密码"
                v-model="registerPassword"
                clearable
                show-password
            />
          </el-form-item>
          <el-form-item>
            <el-input
                type="password"
                placeholder="确认密码"
                v-model="confirmPassword"
                clearable
                show-password
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleRegister">注册</el-button>
          </el-form-item>
        </el-form>
      </div>
      <!-- 登录 -->
      <div class="login-box" :class="{ hidden: isRegister }">
        <h1>LOGIN</h1>
        <el-form
            ref="loginForm"
        >
          <div class="form-header">
            <p class="subtitle">养老服务整合平台</p>
          </div>

          <!-- 账号输入 -->
          <el-form-item prop="username">
            <el-input
                v-model="loginUsername"
                placeholder="请输入账号"
                prefix-icon="User"
                autocomplete="username"
            />
          </el-form-item>

          <!-- 密码输入 -->
          <el-form-item prop="password">
            <el-input
                v-model="loginPassword"
                type="password"
                placeholder="请输入密码"
                prefix-icon="Lock"
                autocomplete="current-password"
                show-password
            />
          </el-form-item>

          <!-- 角色选择 -->
          <el-form-item prop="role">
            <el-select
                placeholder="请选择用户角色"
                class="role-selector"
            >
              <el-option label="管理员" value="管理员"/>
              <el-option label="普通用户" value="普通用户"/>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div class="con-box left">
      <h2>欢迎来到<span>宠物之家</span></h2>
      <p>快来领取你的专属<span>宠物</span>吧</p>
      <img :src="catImage1" alt="">
      <p>已有账号</p>
      <el-button @click="switchToLogin">去登录</el-button>
    </div>
    <div class="con-box right">
      <h2>欢迎来到<span>宠物之家</span></h2>
      <p>快来看看你的可爱<span>宠物</span>吧</p>
      <img :src="catImage2" alt="">
      <p>没有账号？</p>
      <el-button @click="switchToRegister">去注册</el-button>
    </div>
  </div>
</template>

<script>
import catImage1 from '@/assets/images/cat1.png'
import catImage2 from '@/assets/images/cat2.png'
export default {
  data() {
    return {
      registerUsername: "",
      registerEmail: "",
      registerPassword: "",
      confirmPassword: "",
      loginUsername: "",
      loginPassword: "",
      isRegister: false,
      formTranslation: 0,
      catImage1,
      catImage2
    };
  },
  methods: {
    handleRegister() {
      console.log("注册成功！");
    },
    handleLogin() {
      console.log("登录成功！");
    },
    switchToLogin() {
      this.isRegister = false;
      this.formTranslation = 0;
    },
    switchToRegister() {
      this.isRegister = true;
      this.formTranslation = 80;
    },
  },
};
</script>

<style>
* {
  margin: 0;
  padding: 0;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(200deg, #f3e7e9, #e3eeff);
}

.container {
  background-color: #fff;
  width: 650px;
  height: 415px;
  border-radius: 5px;
  box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.1);
  position: relative;
}

.form-box {
  position: absolute;
  top: 20%;
  left: 5%;
  background-color: #d3b7d8;
  width: 320px;
  height: 500px;
  border-radius: 5px;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2;
  transition: 0.5s ease-in-out;
}

.register-box,
.login-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.hidden {
  display: none;
}

h1 {
  text-align: center;
  margin-bottom: 25px;
  text-transform: uppercase;
  color: #fff;
  letter-spacing: 5px;
}

.el-input.el-input--small {
  width: 70%;
  margin: 8px 0;
}

.el-input__inner {
  background-color: transparent;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.4);
  padding: 10px 0;
  text-indent: 10px;
  font-size: 14px;
  letter-spacing: 2px;
}

.el-input__placeholder {
  color: #fff;
}

.el-button:not(.el-button--small) {
  width: 70%;
  margin-top: 35px;
  background-color: #f6f6f6;
  color: #a262ad;
  letter-spacing: 2px;
  border-radius: 8px;
}

.el-button:hover {
  background-color: #a262ad;
  color: #f6f6f6;
}

.con-box {
  width: 50%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

.con-box.left {
  left: -2%;
}

.con-box.right {
  right: -2%;
}

.con-box h2 {
  color: #8e9aaf;
  font-size: 25px;
  font-weight: bold;
  letter-spacing: 3px;
  text-align: center;
  margin-bottom: 4px;
}

.con-box p {
  font-size: 12px;
  letter-spacing: 2px;
  color: #8e9aaf;
  text-align: center;
}

.con-box span {
  color: #d3b7d8;
}

.con-box img {
  width: 150px;
  height: 150px;
  opacity: 0.9;
  margin: 40px 0;
}

.el-button--text {
  background-color: #fff;
  color: #a262ad;
  border: 1px solid #d3b7d8;
  padding: 6px 10px;
  border-radius: 5px;
  letter-spacing: 1px;
  outline: none;
}

.el-button--text:hover {
  background-color: #d3b7d8;
  color: #fff;
}
</style>